package com.practice.system.pojo;

import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.Data;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.io.Serializable;
import java.util.Collection;

@Data
@JsonIgnoreProperties(ignoreUnknown = true)// 告诉序列化器忽略未知的属性
public class User implements Serializable, UserDetails {

    private Integer id;
    //账户名
    private String accountName;
    //密码
    private String password;
    //用户类型
    private Integer userType;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
//        if (authority != null) {
//            return authority;
//        }
//        authority = new ArrayList<>();
//        SimpleGrantedAuthority grantedAuthority = new SimpleGrantedAuthority(this.userType.toString());
//        authority.add(grantedAuthority);
//        return authority;
        return null;
    }

    @Override
    public String getUsername() {
        return this.accountName;
    }

    @Override
    public boolean isAccountNonExpired() {
        return true;
    }

    @Override
    public boolean isAccountNonLocked() {
        return true;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return true;
    }

    @Override
    public boolean isEnabled() {
        return true;
    }
}
